home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Palettes / Chart / Source / BarChart.h next >
Text File  |  1995-06-12  |  11KB  |  233 lines

  1. // -------------------------------------------------------------------------------------
  2. // BarChart.h
  3. // Martin D. Flynn, NeXT Computer, Inc.
  4. // -------------------------------------------------------------------------------------
  5.  
  6. #import <sys/types.h>
  7. #import <objc/Storage.h>
  8.  
  9. // -------------------------------------------------------------------------------------
  10. // chart types (may be logically OR'ed together)
  11. #define    chartLINE            0x01        // line chart
  12. #define    chartPOINT            0x02        // point chart
  13. #define    chartBAR            0x04        // bar chart (along x-axis)
  14. #define    chartAREA            0x08        // area chart
  15.  
  16. // -------------------------------------------------------------------------------------
  17. // default line width
  18. #define    DEFAULT_LINE_WIDTH    -1.0
  19.  
  20. // -------------------------------------------------------------------------------------
  21. // charting data source structure
  22. // The first two elements of this structure must not be modified by any external method call
  23. // Their integrity is set and maintained within the BarChart instance.  The other structure
  24. // elements may be modified as necessary to accomplish the desired effect.
  25. typedef struct chartData_struct {
  26.   int            _srcType;                // data source type (do not modify)
  27.   id            _srcId;                    // id of data source (do not modify)
  28.   int            chartType;                // type of chart to plot
  29.   BOOL            isEditable;                // specifies whether the data source is modifiable
  30.   float            lineWidth;                // the linewidth to plot
  31.   BOOL            isColor;                // chart in color, if TRUE
  32.   NXColor        chartColor;                // the color value to plot
  33. } *chartData_t, chartData_s;
  34.  
  35. // -------------------------------------------------------------------------------------
  36. @interface      BarChart : View
  37. {
  38.  
  39.   // archived variables
  40.   
  41.   NXColor        backgroundColor;        // background color
  42.   NXColor        dftChartColor;            // default chart color
  43.   NXColor        axisColor;                // axis color
  44.   NXColor        xGridColor;                // xGrid color 
  45.   NXColor        yGridColor;                // yGrid color
  46.   
  47.   int            dftChartType;            // default chart type
  48.   NXRect        tickMark;                // (data) tick mark origin/size            
  49.   NXRect        dataRange;                // (data) data range
  50.   id            currentFont;            // current font id
  51.   
  52.   struct _barFlags {
  53.     u_short        drawInColor:1;            // use color to draw
  54.     u_short        transparent:1;            // background transparent
  55.     u_short        xGridDraw:1;            // draw x grid
  56.     u_short        yGridDraw:1;            // draw y grid
  57.     u_short        xShowLabels:1;            // show x axis labels
  58.     u_short        yShowLabels:1;            // show y axis labels
  59.     u_short        xLogScale:1;            // logorithmic scaling on x axis
  60.     u_short        yLogScale:1;            // logorithmic scaling on y axis
  61.     u_short        xLabelRotate:1;            // rotate X-axis labels 90 degrees
  62.     u_short        yLabelRotate:1;            // rotate Y-axis labels 90 degrees
  63.     u_short        _RESERVED:6;            // future use
  64.   }             cFlags;                    // chart flags
  65.  
  66.   // work variables
  67.   
  68.   id            dataList;                // chart data source
  69.   id            delegate;                // chart delegate
  70.  
  71.   id            xLabelMatrix;            // (U/C) xAxis labels
  72.   id            yLabelMatrix;            // (U/C) yAxis labels
  73.   id            actionMatrix;            // matrix containing actions performed when selected
  74.   
  75.   NXSize        xLblSize;                // xAxis label size
  76.   NXSize        yLblSize;                // yAxis label size
  77.   NXPoint        maxRange;                // upper limit on data range
  78.  
  79.   float            tickLength;                // tick mark length
  80.   float            tickWidth;                // tick and axis line width
  81.   NXRect        chartFrame;                // calculated chart frame
  82.   NXPoint        axisOrigin;                // (PS) axis origin point
  83.   NXPoint        axisPosition;            // (PS) axis displayed position
  84.   NXPoint        dataScale;                // (data=>PS) scale factor
  85.   
  86.   int            precisionX;                // label precision for X axis
  87.   int            precisionY;                // label precision for Y axis
  88.   
  89.   BOOL            reScale;                // rescale axis info if true
  90.   BOOL            isFirstResponder;        // first responder flag
  91.   
  92. }
  93.  
  94. // -------------------------------------------------------------------------------------
  95. // chart data source access
  96. - (Storage*)chartList;                    // return Storage object contains chartData_s elements
  97. - (int)chartCount;                        // return number of chartData_s elements
  98. - (chartData_s*)chartDataAt:(int)index;    // return pointer to specified chartData_s elements 
  99.  
  100. // -------------------------------------------------------------------------------------
  101. // logorithmic axis scaling
  102. - (float)log:(float)num;                    // return base-10 log of specified value
  103. - (float)exp:(float)num;                    // return base-10 anti-log of specified value
  104.  
  105. // -------------------------------------------------------------------------------------
  106. // point conversions
  107. - convertDataPointToChart:(NXPoint*)point;    // return data point converted to chart view
  108. - convertChartPointToData:(NXPoint*)point;    // return chart view point converted to data
  109.  
  110. // -------------------------------------------------------------------------------------
  111. // default charting options (IB use)
  112. - setDftChartType:(int)chartType;            // set default carting type
  113. - (int)dftChartType;                        // return default charting type
  114. - setDftChartGray:(float)gray;                // set default chart gray
  115. - (float)dftChartGray;                        // return default chart gray
  116. - setDftChartColor:(NXColor)color;            // set default chart color
  117. - (NXColor)dftChartColor;                    // return default chart color
  118.  
  119. // -------------------------------------------------------------------------------------
  120. // chart axis options
  121. - setDataRange:(NXRect*)range;                // set X/Y axis data range
  122. - (NXRect*)dataRange;                        // return current X/Y axis data range
  123. - setTickMark:(NXRect*)tick;                // set X/Y axis tickMark size (origin not used)
  124. - (NXRect*)tickMark;                        // return current X/Y axis tickMark size
  125.  
  126. // -------------------------------------------------------------------------------------
  127. // point selection/ change delegate
  128. - setDelegate:anObject;                        // set point selection/change delegate
  129. - delegate;                                    // return designated selection/change delegate
  130.  
  131. // -------------------------------------------------------------------------------------
  132. // changing the label font
  133. - setFont:fontId;                            // set the X/Y axis label font
  134. - font;                                        // reutrn the current X/Y label font
  135.  
  136. // -------------------------------------------------------------------------------------
  137. // transparent background
  138. - setBackgroundTransparent:(BOOL)flag;        // set background transparent
  139. - (BOOL)backgroundTransparent;                // return background transparent state
  140.  
  141. // -------------------------------------------------------------------------------------
  142. // axis options
  143. - setXLogScaling:(BOOL)flag;                // set X-axis log scaling
  144. - (BOOL)xLogScaling;                        // return current X-axis log scaling state
  145. - setYLogScaling:(BOOL)flag;                // set Y-axis log scaling
  146. - (BOOL)yLogScaling;                        // return current Y-axis log scaling state
  147. - setXShowLabels:(BOOL)flag;                // set X-axis labels ON/OFF
  148. - (BOOL)xShowLabels;                        // return X-axis labels state
  149. - setYShowLabels:(BOOL)flag;                // set Y-axis labels ON/OFF
  150. - (BOOL)yShowLabels;                        // return Y-axis labels state
  151. - setXGridDraw:(BOOL)flag;                    // set X-axis grid lines ON/OFF
  152. - (BOOL)xGridDraw;                            // return X-axis grid lines state
  153. - setYGridDraw:(BOOL)flag;                    // set Y-axis grid lines ON/OFF
  154. - (BOOL)yGridDraw;                            // return Y-axis grid lines state
  155. - setXLabelRotate:(BOOL)flag;                // rotate X-axis labels 90 degrees
  156. - (BOOL)xLabelRotate;                        // return X-axis label rotate state
  157. - setYLabelRotate:(BOOL)flag;                // rotate Y-axis labels 90 degrees
  158. - (BOOL)yLabelRotate;                        // return Y-axis label rotate state
  159.  
  160. // -------------------------------------------------------------------------------------
  161. // return color/gray draw mode
  162. - (BOOL)drawInColor;                        // return gray/color draw mode
  163.  
  164. // -------------------------------------------------------------------------------------
  165. // gray support (these force drawInColor to NO)
  166. - setBackgroundGray:(float)gray;            // set background gray
  167. - (float)backgroundGray;                    // return current background gray
  168. - setAxisGray:(float)gray;                    // set X/Y axis gray
  169. - (float)axisGray;                            // return current X/Y axis gray
  170. - setXGridGray:(float)gray;                    // set X-axis grid gray
  171. - (float)xGridGray;                            // return current X-axis grid gray
  172. - setYGridGray:(float)gray;                    // set Y-axis grid gray
  173. - (float)yGridGray;                            // return current Y-axis grid gray
  174.  
  175. // -------------------------------------------------------------------------------------
  176. // color support (these force drawInColor to NO)
  177. - setBackgroundColor:(NXColor)color;        // set background color
  178. - (NXColor)backgroundColor;                    // return current background color
  179. - setAxisColor:(NXColor)color;                // set X/Y axis color
  180. - (NXColor)axisColor;                        // return current X/Y axis color
  181. - setXGridColor:(NXColor)color;                // set X-axis grid color
  182. - (NXColor)xGridColor;                        // return current X-axis grid color
  183. - setYGridColor:(NXColor)color;                // set Y-axis grid color
  184. - (NXColor)yGridColor;                        // return current Y-axis grid color
  185.  
  186. // -------------------------------------------------------------------------------------
  187. // chart (re)draw
  188. - update:sender;                            // redraw chart from data source(s)
  189.  
  190. // -------------------------------------------------------------------------------------
  191. // data source support
  192. // These methods may be used to add chart data sources to the barChart instance.
  193. // sourceId may be an instance of Matrix, ScrollView, Text, or Storage.  If anObject is
  194. // an instance of Matrix, then the cells floatValue will be used as the Y-axis value,
  195. // and the cells tag will be used at the X-axis value.  If anObject is an instance of
  196. // ScrollView, then it is checked to make sure that its content view is of type Text.
  197. // If anObject is an instance of Storage, then it is assumed to contain multiple
  198. // elements of NXPoint.
  199. - (int)addDataSource:sourceId type:(int)type lineWidth:(float)width gray:(float)gray;
  200. - (int)addDataSource:sourceId type:(int)type lineWidth:(float)width color:(NXColor)color;
  201.  
  202. // -------------------------------------------------------------------------------------
  203. // data source support
  204. // These methods may be used to add chart data sources supplied by an NXStream.
  205. // Data points are read in x,y pairs from the stream to chart.  Points are separated with
  206. // the new-line character (\n).  If only one point is found on a line, then it is assumed
  207. // to be the Y-axis value, and the X-axis value is assigned from the ordinal value of the
  208. // data point.  
  209. - (int)addDataStream:(NXStream*)s type:(int)type lineWidth:(float)width gray:(float)gray;
  210. - (int)addDataStream:(NXStream*)s type:(int)type lineWidth:(float)width color:(NXColor)color;
  211.  
  212. // -------------------------------------------------------------------------------------
  213. // outlets
  214. - setDataSource:anObject;                    // set data soruce to specified object
  215. - setXLabelMatrix:anObject;                    // set matrix from which to draw X-axis labels 
  216. - xLabelMatrix;                                // return current X-axis label matrix
  217. - setYLabelMatrix:anObject;                    // set matrix from which to draw Y-axis labels
  218. - yLabelMatrix;                                // return current Y-axis label matrix
  219.  
  220. @end
  221.  
  222. // -------------------------------------------------------------------------------------
  223. // bar chart delegate methods
  224. @interface BarChart(delegate)
  225.  
  226. // This method is called when the user double-clicks on a point within an data source.
  227. // If a designated delegate has been specified, then this method is sent to the delegate.
  228. // The default action is to select the coresponding cell in the actionMatrix (if any), then
  229. // send 'sendAction:' to actionMatrix. 
  230. - chartDataSelected:(chartData_s*)chartData index:(int)index;
  231.  
  232. @end
  233.